#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
# include <QTcpSocket>
#include <QMainWindow>
#include <QDebug>
#include <QDialog>
#include <QTcpSocket>
#include <QMessageBox>
#include <QListWidget>
#include<QListWidgetItem>
#include "friendadd.h"
#include "setfriendnickname.h"
#include "frienddelete.h"
#include "uidesign.h"
#include "localprocess.h"
#include "chatcontent.h"


#include "groupcreate.h"
#include "groupinvite.h"
#include "groupjoin.h"


#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonValue>
#include <QFileInfo>
#include <QFile>
#include <QItemSelection>

#include <QtXml>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    explicit MainWindow(QTcpSocket* s, QString Id, QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void updateFriendList();
    void decodeFriendList();

    void PerformUpdateGroupList();
    void updateGroupList();
    void decodeGroupList();

    void PerformUpdateP2PList();
    void update_P2P_ChattingList();
    //void decode_P2P_ChattingList();
    void update_P2P_ChattingList_SINGLE(QString targetID);

    void PerformUpdateP2GList();
    void update_P2G_ChattingList();
    void update_P2G_ChattingList_SINGLE(QString groupID);

    void on_pushButton_clicked();
    void hadrecv();
    void on_closeButton_clicked();


    void on_addFriend_clicked();
    void createrec(QString uName, QString unId, QString nickname);


    
    void on_listWidget_itemDoubleClicked(QListWidgetItem *item);
    void deliver();

    void testDeliver();
    //void writeChat(QString id, QString friendId, QString content);
    //void newChatFriend(QString id);


    void on_deleteFriend_clicked();
    void deleterec(QString unId);

    void on_createGroup_clicked();
    void creategrouprec(QString gName, QString gID);



    void on_joinGroup_clicked();
    void joinGroupRec(QString gName, QString gID);

    void on_inviteGroup_clicked();

    void on_exitGroup_clicked();

    void addWig(QString name, QString fromID, QString time, QString content);

    void on_groupList_itemClicked(QListWidgetItem *item);
    //void judgeCol(QItemSelection first, QItemSelection second);

    void on_confirmFriend_clicked();

    void processFriendQuery();

    void ProcessExitGroup();
    void on_groupList_itemDoubleClicked(QListWidgetItem *item);
    void deliverGroup();
    void testDeliverGroup();
    void performAddFriendSendback(QString uName, QString unId, QString nickname);

private:
    Ui::MainWindow *ui;
    QTcpSocket* sock;
    QTcpSocket* sock_read;
    QStringList listId;
    QStringList listName;
    QStringList listNickName;
    QString communicationId;
    QString communicationGId;
    QString ID;
    QString creatingNickname;
    QStringList listGroupId;
    QStringList listGroupName;
    QStringList listGroupVerify;
    int current_Row;
    QString gID;

    QString targetID_for_updataP2P;

    QString GroupID_for_updataP2G;



    QList<QString> sd_id;
    QList<QString> sd_name;

signals:
    void mainclose();
    void dickadd();
    void FriendListUpdated();
    void GroupListUpdated();
    void P2PChatUpdated();
    void finish();
    void NickNameSet(QString, QString, QString);
};

#endif // MAINWINDOW_H
